mod particle;
mod particle_system;

use ggez::{Context, GameResult, GameError, graphics, glam::Vec2};

pub struct State{
    pss: Vec<particle_system::PraticleSystem>,
}

impl State{
    pub fn new() -> State {
        let pss = vec![];
        State { pss }
    }
}

impl ggez::event::EventHandler<GameError> for State {
    fn update(&mut self, ctx: &mut Context) -> GameResult {
        if ctx.mouse.button_just_pressed(ggez::event::MouseButton::Left) {
            let ps = particle_system::PraticleSystem::new(Vec2 { x: ctx.mouse.position().x, y: ctx.mouse.position().y });
            self.pss.push(ps);
        }
        for ps in &mut self.pss {ps.update()}
        Ok(())
    }
    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let mut canvas = graphics::Canvas::from_frame(ctx, graphics::Color::WHITE);
        for ps in &mut self.pss {ps.display(ctx, &mut canvas)};
        canvas.finish(ctx)?;
        Ok(())
    }
}